import QtQuick
import QtQuick.Controls

Rectangle {
    width: 400
    height: 400

    property var framePaths: attackFrames

    Item {
        id: scene
        anchors.fill: parent

        // 精灵显示
        Image {
            id: spriteDisplay
            width: 327
            height: 327
            anchors.centerIn: parent
            source: framePaths[0]
        }

        // 动画控制
        property int currentFrame: 0
        property bool isPlaying: false

        Timer {
            id: animationTimer
            interval: 100
            running: scene.isPlaying
            repeat: true
            onTriggered: {
                scene.currentFrame = (scene.currentFrame + 1) % framePaths.length;
                spriteDisplay.source = framePaths[scene.currentFrame];
            }
        }
    }

    Column {
        anchors.right: parent.right
        anchors.bottom: parent.bottom
        spacing: 10
        padding: 10

        Button {
            text: scene.isPlaying ? "暂停" : "播放"
            onClicked: scene.isPlaying = !scene.isPlaying
        }

        ComboBox {
            width: 150
            model: ["攻击动画", "行走动画", "奔跑动画"]
            onCurrentIndexChanged: {
                // 这里可以动态切换不同的动画序列
                switch(currentIndex) {
                    case 0: framePaths = attackFrames; break;
                    case 1: framePaths = walkFrames; break;
                    case 2: framePaths = runFrames; break;
                }
                scene.currentFrame = 0;
                spriteDisplay.source = framePaths[0];
            }
        }
    }

    // 不同动画的帧序列
    property var attackFrames: [
        "qrc:/images/hero/hero-pro-attack_0.png",
        "qrc:/images/hero/hero-pro-attack_1.png",
        "qrc:/images/hero/hero-pro-attack_2.png",
        "qrc:/images/hero/hero-pro-attack_3.png",
        "qrc:/images/hero/hero-pro-attack_4.png",
        "qrc:/images/hero/hero-pro-attack_5.png",
        "qrc:/images/hero/hero-pro-attack_6.png",
        "qrc:/images/hero/hero-pro-attack_7.png"
    ]

    property var walkFrames: [
        "qrc:/images/hero/hero-pro-walk_00.png",
        "qrc:/images/hero/hero-pro-walk_01.png",
        "qrc:/images/hero/hero-pro-walk_02.png",
        "qrc:/images/hero/hero-pro-walk_03.png",
        "qrc:/images/hero/hero-pro-walk_04.png",
        "qrc:/images/hero/hero-pro-walk_05.png",
        "qrc:/images/hero/hero-pro-walk_06.png",
        "qrc:/images/hero/hero-pro-walk_07.png",
        "qrc:/images/hero/hero-pro-walk_08.png",
        "qrc:/images/hero/hero-pro-walk_09.png",
        "qrc:/images/hero/hero-pro-walk_10.png",
        "qrc:/images/hero/hero-pro-walk_11.png",
        "qrc:/images/hero/hero-pro-walk_12.png",
        "qrc:/images/hero/hero-pro-walk_13.png",
        "qrc:/images/hero/hero-pro-walk_14.png",
        "qrc:/images/hero/hero-pro-walk_15.png",
        "qrc:/images/hero/hero-pro-walk_16.png",
        "qrc:/images/hero/hero-pro-walk_17.png",
        "qrc:/images/hero/hero-pro-walk_18.png",
        "qrc:/images/hero/hero-pro-walk_19.png",
        "qrc:/images/hero/hero-pro-walk_20.png",
        "qrc:/images/hero/hero-pro-walk_21.png"
    ]

    property var runFrames: [
        "qrc:/images/hero/hero-pro-run_00.png",
        "qrc:/images/hero/hero-pro-run_01.png",
        "qrc:/images/hero/hero-pro-run_02.png",
        "qrc:/images/hero/hero-pro-run_03.png",
        "qrc:/images/hero/hero-pro-run_04.png",
        "qrc:/images/hero/hero-pro-run_05.png",
        "qrc:/images/hero/hero-pro-run_06.png",
        "qrc:/images/hero/hero-pro-run_07.png",
        "qrc:/images/hero/hero-pro-run_08.png",
        "qrc:/images/hero/hero-pro-run_09.png",
        "qrc:/images/hero/hero-pro-run_10.png",
    ]
}
